package org.oop7.jihe;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class zuoye {

	public static void main(String[] args) {
		System.out.println("请输入字符串：");
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String[] attr = str.split("");
		List <String> list = Arrays.asList(attr);
		Set<String>set = new HashSet(list);
		//System.out.println(list);
		//System.out.println(set);
		//找出重复的字符
		String a = "";
		for(int i=0;i<attr.length;i++){
			for(int j=i+1;j<attr.length;j++){
				if(attr[i].equals(attr[j])){
					a += attr[i];
				}
			}
		}
		//先把重复的出现的次数先找出来
		//System.out.println(a);//有重复的先去重
		if(a.length()>0){
			String[] aa = a.split("");
			List lis = Arrays.asList(aa);
			Set se1 = new HashSet(lis);
			//System.out.println(se1);
			Object[] oo = se1.toArray(); 
			for(int i =0;i<oo.length;i++){
				int k=0;
				for(int j=0;j<attr.length;j++){
					if(oo[i].equals(attr[j])){
						k++;
					}
				}
				System.out.println(oo[i]+"出现了"+k+"次");
			}
			//去除掉重复的之后再遍历
			set.removeAll(se1);
			//System.out.println(set.removeAll(se1));
			//System.out.println(set);
			Iterator it=set.iterator();
			while(it.hasNext()){
				System.out.println(it.next()+"出现了1次");
			}
		}else{
			Iterator it=set.iterator();
			while(it.hasNext()){
				System.out.println(it.next()+"出现了1次");
			}
		}
		
		//把重复的转成list集合
		/*List<String> list2 = Arrays.asList(oo);
		System.out.println(list2);
		list.removeAll(list2);
		for(int i=0;i<list.size();i++){
			System.out.println(list.get(i)+"出现了1次");
		}*/
		/*String str = "abcdeafblmbnopawc";
		System.out.println("原字符为："+str);
		String[] attr = str.split("");
		//将字符串类型的数组转成List集合
		List<String> list = Arrays.asList(attr);
		//System.out.println(list);
		Set<String> set = new HashSet(list);
		//System.out.println(set);
		Object[] attr2 = set.toArray();
		//System.out.println(Arrays.toString(attr2));
		String a = "";
		String b = "";
		List list1 = new ArrayList();
		for(int i =0;i<attr2.length;i++){
			a += attr2[i];
			list1.add(attr2[i]);
		}
		System.out.println("消除重复后的字符为："+a);
		for(int i = 0;i<list.size()-1;i++){
			for(int j=i+1;j<list.size();j++){
				if(list.get(i).equals(list.get(j))){
					b +=list.get(j);
				}
			}
		}
		//System.out.println("重复的字符为："+b);
		String[] s1 = b.split("");
		List<String> list11 = Arrays.asList(s1);
		Set<String> set1 = new HashSet(list11);
		Object[] ob=set1.toArray();
		String c = "";
		for(int i = 0;i<ob.length;i++){
			c += ob[i];
		}
		System.out.println("重复的字符为："+c);
		set.removeAll(set1);
		Object[] ob1 = set.toArray();
		String d="";
		for(int i=0;i<ob1.length;i++){
			d += ob1[i];
		}
		System.out.println("不重复的字符为："+d);*/
		//System.out.println("重复的字符为："+list.removeAll(list1));
		//list.removeAll(set);
		// TODO Auto-generated method stub
		/*zuoye_student zstu1 = new zuoye_student("张三","三一班",88.90);
		zuoye_student zstu2 = new zuoye_student("王五","四一班",94.50);
		zuoye_student zstu3 = new zuoye_student("李华","六一班",73);
		zuoye_student zstu4 = new zuoye_student("小军","七一班",98);
		List list = new ArrayList();
		list.add(zstu1);
		list.add(zstu2);
		list.add(zstu3);
		list.add(zstu4);
		System.out.println(list);
		//遍历
		for(int i = 0;i<list.size();i++){
			System.out.println(list.get(i));
		}
		//增强版for循环
		for(Object a : list){
			zuoye_student aa = (zuoye_student)a;
			System.out.println("班级："+aa.classs+" ,姓名："+aa.name+" ,分数："+aa.score);
		}
		//迭代器
		Iterator<zuoye_student> it = list.iterator();
		while(it.hasNext()){
			zuoye_student aa = it.next();
			System.out.println("班级："+aa.classs+" ,姓名："+aa.name+" ,分数："+aa.score);
		}*/
	}

}
